package com.hpeng.basic.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Component;

import com.hpeng.basic.dao.CategoryDao;
import com.hpeng.sys.model.AssetCard;
import com.hpeng.sys.model.Category;
import com.hpeng.util.GenericDaoImpl;
import com.hpeng.util.Pagination;

@Component("categoryDao")
public class CategoryDaoImpl extends GenericDaoImpl<Category,String> implements CategoryDao {
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	public Pagination<Category> getPagination(int pageSize, int pageNumber , String[] hql, String order) {
		Pagination<Category> pagination = null;
		StringBuffer sb = new StringBuffer();
		for(String str : hql){
			sb.append(str);
		}
		pagination = getPagination(sb.toString()+order, null, pageNumber, pageSize );

		return pagination;
	}

	public List<AssetCard> getAssetCardBySql(String sql, String[] str) {
		return jdbcTemplate.queryForList(sql, str);
	}

	//http://www.vikecn.com/Home/blogview.asp?709549-165307.html
	public List<Category> getCategoryBySql(String sql) {
		jdbcTemplate.query(sql, new ResultSetExtractor() {
			
			public Object extractData(ResultSet rs) throws SQLException,
					DataAccessException {
				
				if(rs.next()){
					Category cat = new Category();
					cat.setCatid(rs.getString("catid"));
					
				}
				return null;
			}
		});
		return null;
	}
	
}
